package mmc.resource;

import java.util.Map;
import java.util.TreeMap;

import mmc.Constants;
import mmc.resource.models.collada.ColladaScene;

public class ModelLoader {
private static final Map<String, Model> MODEL_CACHE = new TreeMap<String, Model>();
	
	public static Model load(String url){
		if(Constants.IS_SERVER){//server does not need textures
			new RuntimeException("WARNING: Server tried to load model "+url).printStackTrace();
			return null;
		}
		
		Model mod = MODEL_CACHE.get(url);
		if(mod!=null)
			return mod;
		
		System.out.println("loading model "+url);
		if(url.endsWith(".dae")){
			mod = new ColladaScene(url);
		}else{
			throw new RuntimeException("Unknown filetype: "+url);
		}
		
		MODEL_CACHE.put(url, mod);
		return mod;
	}
	
	public static void clearModelCache(){
		MODEL_CACHE.clear();
	}
}
